﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOAModels;
using TarreOA.TarreOABLL;

public partial class PublicCommunication_AddGroupLinkMan : System.Web.UI.Page
{
    private int pcg_id;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Request.QueryString.Get("pcg_id") != null)
            {
                this.TxtBirthday.Attributes.Add("onfocus", "calendar()");
                pcg_id = int.Parse(Request.QueryString.Get("pcg_id"));
                FindALLComGroup();
                ViewState["pcg_id"] = pcg_id;
            }
        }
    }

    /// <summary>
    /// 查找所有通讯组信息填充通讯组下拉菜单
    /// </summary>
    protected void FindALLComGroup()
    {
        PublicCommunicationGroupService pcgService = new PublicCommunicationGroupService();
        List<PublicCommunicationGrouptb> list = pcgService.findALL();
        if (list != null && list.Count > 0)
        {
            foreach (PublicCommunicationGrouptb pcg in list)
            {
                ListItem item = new ListItem(pcg.PcgName, pcg.PcgId.ToString());
                if (pcg.PcgId == pcg_id)
                {
                    item.Selected = true;
                }
                this.DdlGroup.Items.Add(item);
            }
        }
    }

    protected void BtnAppend_Click(object sender, EventArgs e)
    {
        if (ViewState["pcg_id"] != null)
        {
            pcg_id = (int)ViewState["pcg_id"];
        }
        string cgLinkManName = this.TxtName.Text;
        int comGroupId = int.Parse(Request.Form.GetValues(this.DdlGroup.ClientID)[0]);
        int cgLinkManSec = int.Parse(Request.Form.GetValues(this.DropDownList2.ClientID)[0]);
        DateTime cgLinkManBirthday = DateTime.Now;
        if (!"".Equals(this.TxtBirthday.Text.Trim()))
        {
            try
            {
                cgLinkManBirthday = DateTime.Parse(this.TxtBirthday.Text);
            }
            catch
            {
                ScriptManager.RegisterClientScriptBlock(Page, GetType(), "", "alert('日期输入有错！');", true);
            }
        }
        string cgLinkManName2 = this.TxtName2.Text;
        string cgLinkManDuty = this.TxtDuty.Text;
        string cgLinkManUnitName = this.TxtUnitName.Text;
        string cgLinkManUnitAddress = this.TxtUnitAddress.Text;
        string cgLinkManUnitTelephone = this.TxtUnitTelephone.Text;
        string cgLinkManUnitFacsimile = this.TxtUnitFacsimile.Text;
        string cgLinkManHomeAddress = this.TxtFamilyAddress.Text;
        string cgLinkManHomeTelephone = this.TxtFamilyTelephone.Text;
        string cgLinkManHandset = this.TxtHandset.Text;
        string cgLinkManEmail = this.TxtEmail.Text;
        string cgLinkManQicq = this.TxtOicq.Text;
        string cgLinkManMsn = this.TxtMSN.Text;
        string cgLinkManRemark = this.TxtRemark.Text;
        PublicCommunicationGroupLinkManService pcgLmService = new PublicCommunicationGroupLinkManService();
        if (pcgLmService.saveComGroupLinkManInfo(comGroupId, cgLinkManName, cgLinkManSec, cgLinkManBirthday, cgLinkManName2,
            cgLinkManDuty, cgLinkManUnitName, cgLinkManUnitAddress, cgLinkManUnitTelephone, cgLinkManUnitFacsimile, cgLinkManHomeAddress,
            cgLinkManHomeTelephone, cgLinkManHandset, cgLinkManEmail, cgLinkManQicq, cgLinkManMsn, cgLinkManRemark) == 1)
        {
            Response.Redirect("CommunicationGroupLinkManShow.aspx?pcg_id=" + pcg_id);
        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(Page, GetType(), "", "alert('添加失败，请重试！');", true);
        }
    }
}
